﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class CourseGuideSubMenuBLL : CommonBLL<CourseGuideSubMenuInfo, CourseGuideSubMenuDAL>
    {
        public static List<CourseGuideSubMenuInfo> GetAll(int id)
        {
            return GetList(id).ToList();
        }

        public static IQueryable<CourseGuideSubMenuInfo> GetList(int id)
        {
            using (var dal = new CourseGuideSubMenuDAL(Settings.ConnectionName))
            {
                return dal.SelectQueryable(o => o.MenuId == id).OrderBy(o => o.OrderId);
            }
        }

        public static CourseGuideSubMenuInfo GetByMenuId(int id)
        {
            using (var dal = new CourseGuideSubMenuDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.MenuId == id);
            }
        }

        public static CourseGuideSubMenuInfo Get(int menuId, int id)
        {
            using (var dal = new CourseGuideSubMenuDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.Id == id && o.MenuId == menuId);
            }
        }

        public static CourseGuideSubMenuInfo Get(int id)
        {
            using (var dal = new CourseGuideSubMenuDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.Id == id);
            }
        }

        public static bool Del(int id)
        {
            using (var dal = new CourseGuideSubMenuDAL(Settings.ConnectionName))
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }
    }
}
